package com.sinosoft.dsp.security.account;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.servlet.http.HttpServletRequest;

import com.sinosoft.dsp.system.entity.ISecurityUser;

/**
 * 暴露当前登录用户的管理类
 * 
 * @author 潘巍（PeterPan）
 * @since 2011-5-30 下午11:38:36
 * 
 */
@ManagedBean(name = "currentUserManager")
@SessionScoped
public class CurrentUserManager {
	private ISecurityUser currentUser;

	public ISecurityUser getCurrentAccount() {
		return currentUser;
	}

	// Injecting HttpServletRequest instead of HttpSession as the latter
	// conflicts with a Weld bean on GlassFish 3.0.1
	public void onLogin(ISecurityUser user, HttpServletRequest request) {
		currentUser = user;
		// reward authenticated users with a longer session
		// default is kept short to prevent search engines from driving up # of
		// sessions
		request.getSession().setMaxInactiveInterval(3600);
	}
}
